package com.gimi.cloud.bbp.merchantZone.controller.ueditor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gimi.cloud.bbp.common.utils.reqhead.Util;
import com.gimi.cloud.bbp.commonService.ueditor.JimiActionEnter;
import com.gimi.cloud.bbp.commonService.ueditor.UeditorUpload;
import com.gimi.cloud.bbp.commonService.ueditor.imp.UeditorUploadImp;

/**
 * 
 * @author hetianshou
 * @Version 1.0
 * @Description Ueditor编辑器Controller
 * @create 2018-02-05
 */
@RestController
@RequestMapping(value = "ueditor")
public class UeditorController {
	private static Logger logger = LoggerFactory.getLogger(UeditorController.class);

	@RequestMapping(value = "/action")
	public void ueditorAction(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 获取要处理的类名
		String handleClassName = request.getParameter("handleClassName");
		logger.info("==============>" + handleClassName);
		// 构建一个类
		UeditorUpload ueditorUpload = new UeditorUploadImp();
		if (handleClassName != null && !"".equals(handleClassName)) {
			ueditorUpload = (UeditorUpload) Class.forName(handleClassName).newInstance();
		}
		String configPath = request.getParameter("filePath");
		String configFileName = request.getParameter("configFileName");
		logger.info(configPath);
		JimiActionEnter actionEnter = new JimiActionEnter(request, configPath, configFileName, null, ueditorUpload);
		String result = actionEnter.exec();
		logger.info(result);
		Util.sendResponse(result, response);
	}

}
